import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class Vista extends JFrame{
	
	private JLabel lbladress;
	private JTextField txtadress;
	
	
	private JLabel lblport;
	private JTextField txtport;
	
	private JLabel lblusuario;
	private JTextField txtusuario;
	
	private JTextArea txtcuadro;
	private JPanel panelbotones;
	private JPanel panel;
	
	private JButton boton;


	private Cliente cliente;
	
	public Vista (){
		
		this.setVisible(true);
		this.setLocation(350,350);
		this.setTitle("Cliente");
		this.setSize(700, 400);
		
		lbladress = new JLabel("Address:");
		txtadress = new JTextField(30);
		
		lblport = new JLabel("Port:");
		txtport = new JTextField(30);
		
		lblusuario= new JLabel("Usuario:");
		txtusuario = new JTextField(30);
		
		txtcuadro = new JTextArea();
		boton = new JButton("enviar");
		
		cliente = new Cliente();
		
		Container conte = this.getContentPane();
		
	    panelbotones = new JPanel();
	    panelbotones.setLayout(new GridLayout(3,2,5,5));
	    
	    panel = new JPanel();
	    panel.setLayout(new GridLayout(1,1,5,5));
	    
	    panelbotones.add(lbladress);
	    panelbotones.add(txtadress);
	    
	    panelbotones.add(lblport);
	    panelbotones.add(txtport);
	    
	    panelbotones.add(lblusuario);
	    panelbotones.add(txtusuario);
	    
	    conte.add(panelbotones, BorderLayout.NORTH);
	    
	    conte.add(txtcuadro, BorderLayout.CENTER);
	    
	    panel.add(boton);
	    
	    conte.add(panel, BorderLayout.SOUTH);
	    
	    
	    
	    boton.addActionListener(new ActionListener(){
	    	public void actionPerformed(ActionEvent evt){
	    		if (cliente.enviar(txtusuario.getText())){
	    			System.out.println(txtusuario.getText());	
		    		//txtcuadro.append(cliente.recibir());
	    		}
	    		else 
	    			boton.setEnabled(false);
	    		
	    	}
	    });
	    
	    
	    
	}
}
